<template>
  <!-- 添加或修改首页列数据对话框 -->
  <el-dialog :close-on-click-modal="false" :title="formType" :visible.sync="open" @close="cancel"
             width="700px" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="96px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="展现类型" prop="showType">
            <el-select v-model="form.showType" placeholder="请选择展现类型">
              <el-option
                v-for="dict in showTypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="优先级(倒序)" prop="sort">
            <el-input-number v-model="form.sort" :min="1" placeholder="请输入排序"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="状态">
            <el-radio-group v-model="form.status">
              <el-radio
                v-for="dict in statusOptions"
                :key="dict.dictValue"
                :label="dict.dictValue">{{dict.dictLabel}}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import operationModule from '@/mixins/operation-module'
  import {
    addHome_list,
    updateHome_list
  } from '@/api/basic/home_list'

  export default {
    name: 'add-or-update',
    mixins: [operationModule],
    data() {
      return {
        // 设置属性
        mixinOperationModuleOptions: {
          saveURL: addHome_list, // 提交数据接口，api地址
          updateURL: updateHome_list // 提交数据接口，api地址
        },
        moduleName: 'Home_list',
        open: false,
        // 弹出层标题
        //表单操作类型
        formType: this.$formType.add,
        // 表单参数
        form: {},
        // 展现类型字典
        showTypeOptions: [],
        // 0=正常,1=停用字典
        statusOptions: [],
        // 是否删除字典
        isDeleteOptions: [],
        // 表单校验
        rules: {}
      }
    },
    methods: {
      init(type) {
        this.reset()
        this.open = true
        if (type == this.$formType.add) {
        } else if (type == this.$formType.edit) {
        } else if (type == this.$formType.detail) {
        }
        this.formType = type
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          showType: undefined,
          sort: 1,
          status: '1',
          createBy: undefined,
          createTime: undefined,
          updateBy: undefined,
          updateTime: undefined,
          remark: undefined
        }

        this.resetForm('form')
      },
      cancel() {
        this.$emit('on-close')
        this.open = false
      }
    },
    created() {
      this.reset()
    }
  }
</script>
